package inabit.compiler.parser.grammar;

import inabit.compiler.lexical.TokenClass;

/**Represents a terminal, one instance of a token class and
 *  optionally a value*/
/**@author Rafael Rocha*/
public class Terminal implements Symbol{
	private TokenClass tkClass;
	private String value;
	
	public Terminal(TokenClass tkClass) {
		this.tkClass = tkClass;
	}
	
	public TokenClass getTokenClass() {
		return tkClass;
	}
	
	public void setValue(String value) {
		this.value = value;
	}
	
	/**If the token class is univoque it returns the token representation
	 * on the text file, otherwise it returns the token associated value*/
	public String getValue() {
		if(tkClass == null) {
			return null;
		}else if(tkClass.isUnivoque()) {
			return tkClass.getStateLabel();
		}else {
			return value;
		}
	}
}
